using System.Collections.Generic;

namespace DrawToolsLib {
    /// <summary>
    /// Delete command.
    /// </summary>
    class CommandDeleteAll : CommandBase {
        List<GraphicsBase> cloneList;

        // Create this command BEFORE applying Delete All function.
        public CommandDeleteAll(DrawingCanvas drawingCanvas) {
            cloneList = new List<GraphicsBase>();

            // Make clone of the whole list.
            foreach (GraphicsBase g in drawingCanvas.GraphicsList) {
                cloneList.Add(g);
            }
        }

        /// <summary>
        /// Add all deleted objects to ActiveIcon
        /// </summary>
        public override void Undo(DrawingCanvas drawingCanvas) {
            foreach (GraphicsBase o in cloneList) {
                drawingCanvas.Push(o);
            }
            HelperFunctions.SelectAll(drawingCanvas);
        }

        /// <summary>
        /// Detete All again
        /// </summary>
        public override void Redo(DrawingCanvas drawingCanvas) {
            foreach (GraphicsBase o in cloneList) {
                drawingCanvas.Pop(o);
            }
        }
    }
}
